package com.example.androidframework.ui.exchange.holder

import android.graphics.Paint
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.example.androidframework.R
import com.example.androidframework.databinding.ItemExchangeGoodsBinding
import com.example.androidframework.ui.goods.GoodsDetailActivity
import com.example.androidframework.ui.login.LoginActivity
import com.martin.lib_base.LibBase
import com.martin.lib_base.annotation.ItemData
import com.martin.lib_base.base.BaseViewHolder
import com.martin.lib_base.bean.app.mall.JfGoodsBean
import com.martin.lib_base.interfaces.IItemData
import com.martin.lib_base.ktx.loge


@ItemData(ExchangeGoodsViewHolder.Companion.ItemData::class)
class ExchangeGoodsViewHolder(view: View) :
    BaseViewHolder<JfGoodsBean, ItemExchangeGoodsBinding>(view) {
    override fun onBindViewHolder(position: Int, item: Any?) {
        val goodsBean: JfGoodsBean? = getItemBean(item)
        goodsBean?.let { bean ->
            binding.bean = bean
            // 中划线(删除线)
            binding.oldPrice.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG

            // 加载图片
            val options =
                RequestOptions().placeholder(com.martin.lib_base.R.drawable.common_placeholder_img)   // 加载中的占位图片
                    .fallback(com.martin.lib_base.R.drawable.common_placeholder_img) // url为空时显示的图片
                    .error(com.martin.lib_base.R.drawable.common_placeholder_img)    // 加载失败显示的图片
            Glide.with(itemView.context).load(bean.thumb).apply(options).into(binding.image)

            itemView.setOnClickListener {
                loge("itemView.setOnClickListener")
                // 通知点击事件触发
                notifyItemClick()
            }
        }
    }

    companion object {
        class ItemData : IItemData {
            override fun getItemLayoutId(): Int {
                return R.layout.item_exchange_goods
            }

        }
    }
}